//
//  ViewController.m
//  VCTransitionDemo
//
//  Created by 赵国腾 on 16/4/25.
//  Copyright © 2016年 赵国腾. All rights reserved.
//

#import "FirstViewController.h"
#import "SecondViewController.h"
#import "BouncePresentAnimation.h"
#import "SwipeUpInteractiveTransition.h"
#import "NormalDismissAnimation.h"

@interface FirstViewController ()<SecondViewControllerDelegate, UIViewControllerTransitioningDelegate>

@property (nonatomic, strong) BouncePresentAnimation *bounceAnimation;
@property (nonatomic, strong) NormalDismissAnimation *dismissAnimation;
@property (nonatomic, strong) SwipeUpInteractiveTransition *transitionController;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.bounceAnimation = [BouncePresentAnimation new];
    self.dismissAnimation = [NormalDismissAnimation new];
    self.transitionController = [SwipeUpInteractiveTransition new];
}

- (IBAction)buttonClick:(UIButton *)sender {
    
    // 01.显示控制器
    SecondViewController *secondCtrl = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    secondCtrl.delegate = self;
    secondCtrl.transitioningDelegate = self;
    secondCtrl.modalPresentationStyle = UIModalPresentationCustom;
    
    [self.transitionController wireToViewController:secondCtrl];
    
    [self presentViewController:secondCtrl animated:YES completion:NULL];
    
}

#pragma mark - <SecondViewControllerDelegate>

- (void)secondViewControllerDisappear:(SecondViewController *)viewController {
    
    [self dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark - UIViewControllerTransitioningDelegate

// 02.实现transitioningDelegate代理方法
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                   presentingController:(UIViewController *)presenting
                                                                       sourceController:(UIViewController *)source {

    return self.bounceAnimation;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{

    
    return self.dismissAnimation;
}

//- (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator{
//    
//    return nil;
//}

- (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{
    
    return self.transitionController;
}

//- (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source NS_AVAILABLE_IOS(8_0){
//    
//    return nil;
//}


@end
